home *** CD-ROM | disk | FTP | other *** search
/ Language/OS - Multiplatform Resource Library / LANGUAGE OS.iso / gnu / glibc108.gz / glibc108 / glibc-1.08.1 / time / emkdir.c < prev    next >
C/C++ Source or Header  |  1993-12-02  |  2KB  |  86 lines

  1. #ifndef lint
  2. #ifndef NOID
  3. static char    elsieid[] = "@(#)emkdir.c    8.21";
  4. #endif /* !defined NOID */
  5. #endif /* !defined lint */
  6.  
  7. #ifndef emkdir
  8.  
  9. /*LINTLIBRARY*/
  10.  
  11. #include "private.h"
  12.  
  13. extern char *    imalloc P((int n));
  14. extern void    ifree P((char * p));
  15.  
  16. static char *
  17. quoted(name)
  18. register const char *    name;
  19. {
  20.     register char *    result;
  21.     register char *    cp;
  22.     register int    c;
  23.  
  24.     if (name == NULL)
  25.         name = "";
  26.     result = imalloc(4 * strlen(name) + 3);
  27.     if (result == NULL)
  28.         return NULL;
  29.     cp = result;
  30. #ifdef unix
  31.     *cp++ = '\'';
  32.     while ((c = *name++) != '\0')
  33.         if (c == '\'') {
  34.             *cp++ = c;
  35.             *cp++ = '\\';
  36.             *cp++ = c;
  37.             *cp++ = c;
  38.         } else    *cp++ = c;
  39.     *cp++ = '\'';
  40. #endif /* defined unix */
  41. #ifndef unix
  42.     while ((c = *name++) != '\0')
  43.         if (c == '/')
  44.             *cp++ = '\\';
  45.         else    *cp++ = c;
  46. #endif /* !defined unix */
  47.     *cp = '\0';
  48.     return result;
  49. }
  50.  
  51. int
  52. emkdir(name, mode)
  53. const char *    name;
  54. const int    mode;
  55. {
  56.     register int        result;
  57.     register const char *    format;
  58.     register char *        command;
  59.     register char *        qname;
  60.  
  61.     if ((qname = quoted(name)) == NULL)
  62.         return -1;
  63. #ifdef unix
  64.     format = "mkdir 2>&- %s && chmod 2>&- %o %s";
  65. #endif /* defined unix */
  66. #ifndef unix
  67.     format = "mkdir %s";
  68. #endif /* !defined unix */
  69.     command = imalloc(strlen(format) + 2 * strlen(qname) + 20 + 1);
  70.     if (command == NULL) {
  71.         ifree(qname);
  72.         return -1;
  73.     }
  74.     (void) sprintf(command, format, qname, mode, qname);
  75.     ifree(qname);
  76.     result = system(command);
  77.     ifree(command);
  78.     return (result == 0) ? 0 : -1;
  79. }
  80.  
  81. /*
  82. ** UNIX is a registered trademark of AT&T.
  83. */
  84.  
  85. #endif /* !defined emkdir */
  86.